<?php 
    class ArticleCategoryTableModel extends Table
	{
		function __construct()
		{
			parent::__construct('bg_articles_categories');
		}
		
		function addArticleCategory(ArticleCategory $category)
		{
			$data=array('article_category_name'=>$category->_article_category_name,'article_category_description'=>$category->_article_category_description,
				'article_category_image'=>$category->_article_category_image,'article_category_parent'=>$category->_article_category_parent,
				'article_category_position'=>$category->_article_category_position,'article_category_status'=>$category->_article_category_status);
			return $this->insert($data);
		}
		
		function getCategoryDropDown($id=0,$parent_id=0,$prefix='',$text='-- Chọn danh mục cha --')
		{
			$html='';
			if($parent_id==0)
			{
				$html.='<select name="categoryParent" class="postform">';
				if(!empty($text))
				{
					$html.='<option value="0">'.$text.'</option>';
				}
			}
			$column=array('article_category_id','article_category_name');
			$orderby=array('article_category_position'=>'ASC');
			$where=array('article_category_parent'=>$parent_id);
			$data=$this->select('assoc', $column, $where, $orderby);
			if($data!=null && count($data) > 0)
			{
				foreach($data as $d)
				{
					$selected=$d['article_category_id']==$id?'selected="selected"':'';
					$html.='<option value="'.$d['article_category_id'].'" '.$selected.'>'.$d['article_category_name'].'</option>';
					$html.=$this->getCategoryDropDown($id,$d['article_category_id'],$prefix.'--','');
				}
			}
			if($parent_id==0)
			{
				$html.='</select>';
			}
			return $html;
		}
	}
?>